package com.example.administrator.androidui4;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import static com.example.administrator.androidui4.R.id.btn_my;
import static com.example.administrator.androidui4.R.id.btn_my;

public class MainActivity extends AppCompatActivity {
    String[] furits=new String[]{"苹果","西瓜","桃子"};

class MyButtonListener implements View.OnClickListener{


    @Override
    public void onClick(View v) {
        Toast.makeText(MainActivity.this, "内部类点击事件处理", Toast.LENGTH_SHORT).show();
    }
}
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


      Button btnMyDialog = findViewById(R.id.btn_my);
      btnMyDialog.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              MyDialog dialog = new MyDialog(MainActivity.this);
              dialog.show();
          }
      });


        Button btnprogressDialog = findViewById(R.id.btn_progress_dialog);//获取这个按钮
        btnprogressDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ProgressDialog progressDialog=new ProgressDialog(MainActivity.this);
                progressDialog.setMessage("加载中。。。。");
                progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                progressDialog.show();

            }
        });

    Button button1=findViewById(R.id.btn_button1);

    button1.setOnClickListener(new View.OnClickListener() {

        @Override

        public void onClick(View v) {
            Toast.makeText(MainActivity.this,
                    "匿名内部类对象",
                    Toast.LENGTH_SHORT).show();
        }
    });
    Button button2=findViewById(R.id.btn_button2);
    button2.setOnClickListener(new MyButtonListener());

RadioGroup rgsex=findViewById(R.id.rg_sex);
rgsex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        Toast.makeText(MainActivity.this,  checkedId+"", Toast.LENGTH_SHORT).show();
    if(checkedId == R.id.rb_male){
        Toast.makeText(MainActivity.this, "男", Toast.LENGTH_SHORT).show();
    }
    if(checkedId == R.id.rb_female){
        Toast.makeText(MainActivity.this, "女", Toast.LENGTH_SHORT).show();
    }
    }
});


Button btnAlertDialog = findViewById(R.id.btn_alert_dialog);
btnAlertDialog.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        AlertDialog.Builder builder
                = new AlertDialog.Builder(MainActivity.this);
        builder.setTitle("警告框");
      //  builder.setMessage("你是否确认真的删除");
        /*builder.setSingleChoiceItems(furits, -1, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, furits[which], Toast.LENGTH_SHORT).show();
            }
        });*/

        builder.setMultiChoiceItems(furits, null, new DialogInterface.OnMultiChoiceClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                Toast.makeText(MainActivity.this, furits[which]+isChecked, Toast.LENGTH_SHORT).show();
            }
        });
        builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(MainActivity.this, "确认被点击", Toast.LENGTH_SHORT).show();
            }
        });
               builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                   @Override
                   public void onClick(DialogInterface dialog, int which) {
                       Toast.makeText(MainActivity.this, "取消被点击", Toast.LENGTH_SHORT).show();
                   }
               });
               builder.setIcon(R.mipmap.ic_launcher);
        AlertDialog dialog = builder.create();
        dialog.show();
    }
});

}

    public void click(View view) {
        Toast.makeText(this, "按钮被点击了", Toast.LENGTH_SHORT).show();
    }
}
